<template>
	<view class="wrapper">
		<dlContacts ref="jContacts" :myList="myList" @confirm="contactsConfirm"></dlContacts>
	</view>
</template>

<script>
	import dlContacts from '@/components/dl-contacts/dl-contacts.vue';
	import WEBIM from '@/common/webim.js';
	export default {
		data() {
			return {
				myList:[],
				roomid:'',
				qunzhuid:'',
				clist:[]
			};
		},
		components: {
			dlContacts
		},
		onLoad(e) {
			this.roomid=e.roomid
			this.qunzhuid=e.qunzhuid
			this.getFriendList()
		},
		methods:{
			getFriendList() {
				const that = this;
				this.$ajax(this.apiList.friendsList, {
					userId: uni.getStorageSync('userinfo').userId
				}).then(res => {
					res.data = res.data.filter(item => {
						return item.toNickname != '客服公众号';
					});
					this.myList = res.data;
					setTimeout(function() {
						that.$refs.jContacts.show();
					}, 300);
				});
			},
			contactsConfirm(res) {
				console.log(res);
				res.map(item=>{
					// 发送名片
					var msg = WEBIM.createMessage(8, item.toNickname, this.roomid, uni.getStorageSync('userinfo').nickname, 'groupchat');
					msg.objectId=item.toUserId
					msg.id=msg.messageId
					msg.to=this.roomid
					msg.toJid=this.roomid
					WEBIM.sendMessage(msg);
				})
				this.$sToast('发送成功')
				this.$back(1,2500)
			}
		}
	}
</script>

<style lang="scss">

</style>
